package com.ojoin.trade.common_core.web.dao.impl;

import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.ojoin.trade.common.exception.BusinessException;
import com.ojoin.trade.common.exception.DaoException;
import com.ojoin.trade.common.web.dao.impl.BaseDaoImpl;
import com.ojoin.trade.common_core.web.dao.TbFactoringOperatorDao;
import com.ojoin.trade.common_core.web.domain.TbFactoringOperator;

@Repository
public class TbFactoringOperatorDaoImpl extends BaseDaoImpl<TbFactoringOperator> implements TbFactoringOperatorDao {
	
	public SqlSession getSqlSession() {
		return this.sqlSessionTemplate;
	}
	
	@Override
	public TbFactoringOperator queryOperatorUserByNameAndPwd(String name, String pwd)
			throws BusinessException {
		String mapMethodName = "queryOperatorUserByNameAndPwd";
		try {
			HashMap<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("name", name);
			paramMap.put("pwd", pwd);
			List list = this.sqlSessionTemplate.selectList(getSqlName(mapMethodName),
					paramMap);
			if (list != null && list.size() >0)
				return (TbFactoringOperator) list.get(0);
		} catch (Exception e) {
			throw new DaoException(String.format("保理员" + name + "登陆出错！语句：%s",
					getSqlName(mapMethodName)), e);
		}
		
		return null;
	}

	@Override
	public TbFactoringOperator queryOperatorUserByName(String name)
			throws BusinessException {
		String mapMethodName = "queryOperatorUserByName";
		try {
			List list = this.sqlSessionTemplate.selectList(getSqlName(mapMethodName),
					name);
			if (list != null && list.size() >0)
				return (TbFactoringOperator) list.get(0);
		} catch (Exception e) {
			throw new DaoException(String.format("保理员" + name + "查询出错！语句：%s",
					getSqlName(mapMethodName)), e);
		}
		
		return null;
	}
	
}
